package com.atguigui.leetcode;

/**
 * 769.最多能完成排序的块
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/10/13 8:55
 */
public class P769MaxChunksToMakeSorted {

    public static void main(String[] args) {
        Solution solution = new P769MaxChunksToMakeSorted().new Solution();
        // TO TEST
    }

    class Solution {
        public int maxChunksToSorted(int[] arr) {
            int m = 0, res = 0;
            for (int i = 0; i < arr.length; i++) {
                m = Math.max(m, arr[i]);
                //碰到递增就+1
                if (m == i) {
                    res++;
                }
            }
            return res;
        }
    }
}
